<template>
  <!-- 预上传界面 -->
  <VideoUploadStart v-if="!isUploaded" @start-upload="handleStartUpload" />

  <VideoUploadComplete
    v-else
    :upload-id="uploadId"
    :file="file"
    :chunk-count="chunkSize"
    @upload-completed="handleUploadCompleted"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import VideoUploadStart from '@/views/front/upload/VideoUploadStart.vue'
import VideoUploadComplete from '@/views/front/upload/VideoUploadComplete.vue'

// 状态管理
const isUploaded = ref(false)
const uploadId = ref<string>('')
const file = ref<File | null>(null)
const chunkSize = ref<number>(0)

// 处理预上传完成后的逻辑
const handleStartUpload = (result: any) => {
  if (result.code === '0') {
    uploadId.value = result.data
    file.value = result.file
    chunkSize.value = result.chunkSize
    isUploaded.value = true
    console.log(uploadId.value)
  } else {
    ElMessage.error('预上传失败，请稍后再试')
  }
}
// 处理上传完成后的逻辑
const handleUploadCompleted = () => {
  ElMessage.success('视频上传完成！')
  // 可以在这里重置状态或执行其他操作
}
</script>

<style scoped lang="scss"></style>
